<template>
    <div>
        <TablePart :table="table | ignoredField(ignored)" :stripe="stripe"></TablePart>
        <Spin size="large" fix v-if="spinShow"></Spin>
    </div>
</template>

<script>
import TablePart from "_c/TablePart";
import { IViewTable } from "_i";
import { LANG_CODE, RESULT_CODE } from "@/config";
import { Get } from "../api";
let that = null;
export default {
  name: "StatusPart",
  components: { TablePart },
  data() {
    return {
      resultCode:RESULT_CODE,
      langCode:LANG_CODE,
      table: new IViewTable(
        [
          {
            title: "#",
            key: "solution_id",
            width: 30
          },
          {
            title: "账号",
            key: "username"
          },
          {
            title: "题号",
            key: "problem_id",
            width: 50
          },
          {
            title: "语言",
            key: "language",
            width: 50,
            type:"enum",
            enum:LANG_CODE
          },
          {
            title: "结果",
            key: "result",
            width: 50,
            type: "tag",
            colors: { 正确: "success", 语法错误: "error" },
            defaultColor: "warning"
          },
          {
            title: "通过率",
            key: "pass_rate",
            width: 50
          },
          {
            title: "提交时间",
            key: "in_date"
          }
        ],
        []
      ),
      spinShow: false
    };
  },
  props: {
    ignored: {
      type: Array,
      default: () => []
    }, //忽略的列
    stripe: {
      type: Boolean,
      default: true
    }, //斑马线
    filterAnd: {
      //过滤条件与
      type: Array,
      default: () => []
    },
    filterOr: {
      //过滤条件或
      type: Array,
      default: () => []
    },
    orderBy: {
      //排序规则
      type: Object,
      default: () => ({
        field: "in_date",
        mode: "DESC"
      })
    },
    page: {
      type: Object,
      default: () => ({
        page_num: 1, //页码
        page_size: 10, //页的大小
        page_total: 10 //总页数
      })
    },
    funs: {
      type: Object
    }
  },
  filters: {
    ignoredField(value, ignored = []) {
      ignored.forEach(function(item) {
        value.columns[item].disabled = true;
      });
      return value;
    }
  },
  methods: {
    async update() {//更新函数
      this.spinShow = true;
      let { filterAnd, filterOr, orderBy, page } = this.$props;
      let res = await Get.getSolutionList({
        filterAnd,
        filterOr,
        orderBy,
        ...page
      });
      console.log(res);
      this.page.page_total = res.page_total;
      this.table.data = res.data.map(item=>{
          item.result = RESULT_CODE[item.result];
          return item;
      });
      this.spinShow = false;
    }
  },
  async created() {
    that = this;
    this.funs.update = () => {
      this.update();
    };
  }
};
</script>

<style lang="less" scoped>
</style>